//
//  JQFYSpecialDetailsViewController.m
//  JQFY
//
//  Created by 代辉 on 2017/10/31.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYSpecialDetailsViewController.h"
#import "JQFYSpecialDetailsTableViewCell.h"
#import "JQFYSpecialHeader.h"

@interface JQFYSpecialDetailsViewController () <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,weak) UIImageView *topImgView;

@end

static NSString *speical_cell = @"speical_cell";

@implementation JQFYSpecialDetailsViewController

- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [UITableView new];
        [_tableView registerClass:[JQFYSpecialDetailsTableViewCell class] forCellReuseIdentifier:speical_cell];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI
{
    self.title = @"专辑详情";
    UIImageView *topImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"special_detaile"]];
    [self.view addSubview:topImgView];
    [topImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
    }];
    
    self.topImgView = topImgView;
    UIImageView *detaileImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"专辑封面"]];
    
    [self.view addSubview:detaileImgView];
    [detaileImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(10 *SCAL);
        make.bottom.equalTo(topImgView).offset(-10 *SCAL);
        make.width.height.mas_equalTo(120 *SCAL);
    }];
    
    UILabel *specialNameLabel = [UILabel new];
    specialNameLabel.numberOfLines = 2;
    specialNameLabel.text = @"CowgirBlues";
    specialNameLabel.textColor = [UIColor colorWithHex:0xFFFFFF];
    specialNameLabel.font = [UIFont systemFontOfSize:28];
    [self.view addSubview:specialNameLabel];
    [specialNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detaileImgView);
        make.left.equalTo(detaileImgView.mas_right).offset(10 *SCAL);
        make.width.mas_equalTo(100 *SCAL);
    }];
    
    UIButton *collectButton = [UIButton new];
    [collectButton setTitle:@"收藏" forState:UIControlStateNormal];
    [collectButton setTitle:@"已收藏" forState:UIControlStateSelected];
    [collectButton setBackgroundImage: [UIImage imageNamed:@"收藏按钮"] forState:UIControlStateNormal];
    [collectButton setTitleColor:[UIColor colorWithHex:0x6C4CE6] forState:UIControlStateNormal];
    [collectButton setTitleColor:[UIColor colorWithHex:0x6C4CE6] forState:UIControlStateSelected];
    [collectButton addTarget:self action:@selector(collectButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:collectButton];
    [collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detaileImgView);
        make.right.equalTo(self.view).offset(-10 *SCAL);
    }];
    
    UILabel *specialSingerLabel = [UILabel new];
    specialSingerLabel.text = @"Kitie Ellen";
    specialSingerLabel.textColor = [UIColor whiteColor];
    specialSingerLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:specialSingerLabel];
    [specialSingerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(specialNameLabel);
        make.top.equalTo(specialNameLabel.mas_bottom).offset(20 *SCAL);
    }];
    
    UILabel *specialSecondSingerLabel = [UILabel new];
    specialSecondSingerLabel.text = @"Indie Rock";
    specialSecondSingerLabel.font = [UIFont systemFontOfSize:18];
    specialSecondSingerLabel.textColor = [UIColor darkGrayColor];
    [self.view addSubview:specialSecondSingerLabel];
    [specialSecondSingerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(specialSingerLabel);
        make.top.equalTo(specialSingerLabel.mas_bottom).offset(3 *SCAL);
    }];
    
    UIImageView *rightImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"RightArrow"]];
    [self.view addSubview:rightImg];
    [rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(collectButton);
        make.bottom.equalTo(specialSecondSingerLabel.mas_top).offset(3 *SCAL);
    }];
    
    UIView *currentView = [UIView new];;
    currentView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:currentView];
    [currentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.equalTo(specialSecondSingerLabel);
        make.right.equalTo(rightImg);
        make.top.equalTo(specialSingerLabel);
    }];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [currentView addGestureRecognizer:tap];
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topImgView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    self.tableView.sectionHeaderHeight = 44 *SCAL;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.sectionFooterHeight = 0;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JQFYSpecialDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:speical_cell forIndexPath:indexPath];
    cell.indexPath = indexPath;
    cell.songInfo = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    JQFYPlayViewController *player = [JQFYPlayViewController new];
#warning 需要具体设置
    [[NSNotificationCenter defaultCenter] postNotificationName:@"recommendMusicPlay" object:indexPath];
    [self.navigationController presentViewController:player animated:YES completion:nil];
}
#pragma mark - 组头 -
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    JQFYSpecialHeader *header = [[JQFYSpecialHeader alloc] initWithFrame:CGRectMake(0, 0, DH_Screen_Width, 44)];
    return header;
}

#pragma mark - 用于跳转到音乐人详情界面 -
- (void)tap:(UITapGestureRecognizer *)tap
{
    NSLog(@"tap");
}
- (void)collectButtonAction:(UIButton *)button
{
    button.selected = !button.selected;
    NSLog(@"收藏")
}
@end
